package com.ys.ali;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;
import com.ys.utils.alipay.AliPayHandler;
import com.ys.utils.alipay.model.AliNotifyAppInfo;
import com.ys.utils.alipay.model.MsgInfo;
import com.ys.utils.base.j2se.JsonUtil;
import org.junit.jupiter.api.Test;
import org.nutz.json.Json;

import java.util.Date;
import java.util.Map;

/**
 * @Author 但何非
 * @Date 2022/10/26 22:14
 * @ClassName: AliText
 * @Description:
 * @Version:
 */
public class AliText {
    @Test
    public void a(){
        AliPayHandler aliPayHandler = new AliPayHandler("test");
        try {
            AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
            model.setOutBizNo("CS2023042401");
            model.setRemark("测试");
            model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}");
            model.setBizScene("DIRECT_TRANSFER");
            Participant payeeInfo = new Participant();
            payeeInfo.setIdentity("15111986102");
            payeeInfo.setIdentityType("ALIPAY_LOGON_ID");
            payeeInfo.setName("但何非");
            model.setPayeeInfo(payeeInfo);
            model.setTransAmount("0.1");
            model.setProductCode("TRANS_ACCOUNT_NO_PWD");
            model.setOrderTitle("测试");
            MsgInfo msgInfo = aliPayHandler.trans("2021003187690103",model);
            System.err.println(Json.toJson(msgInfo));
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void a1(){
        AliPayHandler aliPayHandler = new AliPayHandler("test");
        try {
            JSONObject bizContent = aliPayHandler.bizContent("20221027010100112","0.01","测试","","webPay","");
//            MsgInfo msgInfo = aliPayHandler.appPay("2021003157650254",bizContent,"https://api.ys168.vip/onlinePay/recharge/notify/zfb");
            MsgInfo msgInfo = aliPayHandler.webPay("2021003157650254",bizContent);
            System.err.println(msgInfo.msg);
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
    }
    @Test
    public void a2(){
        String a = "{\"gmt_create\":\"2022-11-01 21:41:25\",\"charset\":\"UTF-8\",\"seller_email\":\"jzlgod529603@163.com\",\"subject\":\"商品\",\"sign\":\"brU3cM3rUYJ20FE7gfNDzfTol1FL4ldmuStETeyxiSIdZxyVu9MkzUnDSj6ohxw37gm/xlAnPlz4zt7gdEaKEw3VE0IM34tL6h0PZvDhCMPT3NMN6qJxLQn6YRbWNMr7W/znTzBtXpWcCBSOHdWGexTGx4yYb06YkL3ukBknZEBnbcnaA8R8VWuotrdDprBMIx5DcL+2l86DXFuW4FjIDtTW9DCXsh06I0k66oe9lZXCTVZ+ECKlGaO3tAq7G7N/nOK6n8i3Nr+gKdSyivrGe1BIlp0vIYNSX+Kg/yb7OhGFSgBTwWT23cpQ0uLb1AMyfnacCNS4Y9crUP+SELjDlQ==\",\"buyer_id\":\"2088702756850781\",\"invoice_amount\":\"10.00\",\"notify_id\":\"2022110101222214125050781490651445\",\"fund_bill_list\":\"[{\\\"amount\\\":\\\"10.00\\\",\\\"fundChannel\\\":\\\"ALIPAYACCOUNT\\\"}]\",\"notify_type\":\"trade_status_sync\",\"trade_status\":\"TRADE_SUCCESS\",\"receipt_amount\":\"10.00\",\"app_id\":\"2021003157650254\",\"buyer_pay_amount\":\"10.00\",\"sign_type\":\"RSA2\",\"seller_id\":\"2088541102821785\",\"gmt_payment\":\"2022-11-01 21:41:25\",\"notify_time\":\"2022-11-01 21:41:25\",\"version\":\"1.0\",\"out_trade_no\":\"20221101310075537344506\",\"total_amount\":\"10.00\",\"trade_no\":\"2022110122001450781429839941\",\"auth_app_id\":\"2021003157650254\",\"buyer_logon_id\":\"894***@qq.com\",\"point_amount\":\"0.00\"}";
        AliNotifyAppInfo notifyInfo = JsonUtil.jsonToBean(a,AliNotifyAppInfo.class);
        Map<String,String> notifyInfo1 = JsonUtil.jsonToBean(a, Map.class);
        AliPayHandler aliPayHandler = new AliPayHandler("test");
        try {
            aliPayHandler.appNotify(notifyInfo,"E:\\\\alipay\\sphw\\alipayCertPublicKey_RSA2.crt");
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void a3(){
        Date addTime = com.ys.utils.base.j2se.DateUtil.getHourAfterTime(-24);
        System.err.println(com.ys.utils.base.j2se.DateUtil.getDate(addTime,"yyyy-MM-dd HH:mm:ss"));

    }
    @Test
    public void a4(){
        Boolean b = Boolean.parseBoolean("false");
        System.err.println(b);
        b = Boolean.parseBoolean("true");
        System.err.println(b);
    }

}
